package com.example.servicedemo;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.util.Log;

import androidx.annotation.NonNull;

public class MyService2 extends Service {

    private MyHandler myHandler;

    private Messenger messenger;

    private static final String TAG = "MyService2";

    public MyService2() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        myHandler = new MyHandler();
        messenger = new Messenger(myHandler);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return messenger.getBinder();
    }

    private static class MyHandler extends Handler {
        // 处理消息（Service接收到的）
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            Log.i(TAG, "handleMessage:" + msg);
            // 根据不同的消息处理
            switch (msg.what) {

            }

        }
    }

}